import React, { Suspense, lazy } from 'react';
import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom';

// 使用 lazy 懒加载组件
const Yby = lazy(() => import('../pages/yby/Yby'));
const Ljx = lazy(() => import('../pages/ljx/Ljx'));
const Wxd = lazy(() => import('../pages/wxd/Wxd'));
const Zyw = lazy(() => import('../pages/zyw/Zyw'));

// 加载中的显示组件
const LoadingPage = () => (
  <div style={{
    display: 'flex',
    justifyContent: 'center',
    alignItems: 'center',
    height: '100vh',
    fontSize: '20px'
  }}>
    正在加载中...
  </div>
);

const Router: React.FC = () => {
  return (
    <BrowserRouter>
      <Suspense fallback={<LoadingPage />}>
        <Routes>
          {/* 默认重定向到 /yby */}
          <Route path="/" element={<Navigate to="/wxd" replace />} />
          
          {/* 定义各个页面的路由 */}
          <Route path="/yby" element={<Yby />} />
          <Route path="/ljx" element={<Ljx />} />
          <Route path="/wxd" element={<Wxd />} />
          <Route path="/zyw" element={<Zyw />} />

          {/* 处理404情况 */}
          <Route path="*" element={<Navigate to="/wxd" replace />} />
        </Routes>
      </Suspense>
    </BrowserRouter>
  );
};

export default Router; 